package com.moyun.search.controller;

import com.moyun.search.bo.SearchBO;
import com.moyun.search.common.base.BaseController;
import com.moyun.search.common.result.Result;
import com.moyun.search.common.result.ResultUtil;
import com.moyun.search.common.utils.ValidUtil;
import com.moyun.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 查询接口
 * @author: zealon
 * @since: 2021/12/24
 */
@RestController
public class SearchController extends BaseController {

    @Autowired
    private SearchService searchService;

    @GetMapping("search")
    public Result search(@Valid SearchBO bo, BindingResult result) {
        if (result.hasFieldErrors()) {
            return ResultUtil.paramError(ValidUtil.getErrorMessages(result.getFieldErrors()));
        }
        return this.searchService.search(bo);
    }
}